package top.tsyz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tsyz.entity.Product;
import top.tsyz.service.IProductService;

import java.util.List;

/**
 * ProductController控制器
 */
@RestController
@RequestMapping("/api/products")
@Api(tags = "Product管理接口")
public class ProductController {

    @Autowired
    private IProductService iproductservice;

    @GetMapping("/list")
    @ApiOperation("获取所有Product")
    public List<Product> list() {
        return iproductservice.list();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取Product")
    public Product getById(@PathVariable Long id) {
        return iproductservice.getById(id);
    }

    @PostMapping
    @ApiOperation("新增Product")
    public boolean save(@RequestBody Product product) {
        return iproductservice.save(product);
    }

    @PutMapping
    @ApiOperation("更新Product")
    public boolean update(@RequestBody Product product) {
        return iproductservice.updateById(product);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除Product")
    public boolean delete(@PathVariable Long id) {
        return iproductservice.removeById(id);
    }
}
